#include "Space.h"
#include "Player.h"

Space::Space()
{	
}

Space::Space(Property* a_property, char* a_name, int a_price)
{
	m_property = a_property;
	m_name = a_name;
	m_price = a_price;
}

void Space::Draw()
{
	const int width = 20;
	const int height = 6;
	int x = SPACE_POSX;
	int y = SPACE_POSY;

	// Draw the box around the outside
	for(int i = 1; i < height; i++)
	{
		// Left line, blank, right line
		gotoXY(x, y+i);
		printf("|                   |");
	}

	// Top line
	gotoXY(x+1, y);
	printf("---Current Space---");

	// Bottom line
	gotoXY(x+1, y+height);
	printf("-------------------");

	// Draw the name
	gotoXY(++x, ++y);
	printf("%s", m_name);

	// If it actually IS a property..
	if(m_property != 0)
	{
		int houses = m_property->getHouses();
		int owner = m_property->getOwner();

		// Draw the rent
		gotoXY(x, ++y);
		printf("Rent: %d", m_property->getRent(0));
		
		// Draw how many houses are on the property (Only on housable properties)
		if(houses != -1)
		{
			gotoXY(x, ++y);
			printf("Houses: %d", houses);
		}

		// Draw who it's owned by
		gotoXY(x, ++y);
		if(owner == -1)
			printf("Unowned       ");
		else
			printf("Owned by: P%d", owner+1);
			
	}
}

int Space::getPrice() { return m_price; }
char* Space::getName() { return m_name; }

Property* Space::BuyProperty(Player* a_buyer)
{
	a_buyer->PayBank(m_price);
	m_property->setOwner(a_buyer);

	return m_property;
}

// Returns -2 if it's not a property
int Space::getOwner() 
{ 
	if(m_property == 0)
		return -2;

	return m_property->getOwner();
}

int Space::getColor()
{
	// Not a property
	if(m_property == 0)
		return -1;

	return m_property->getColor();
}
